/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.tshirtcannon;

/**
 * abstract class that all the t-shirt cannon state extend.
 * @see TShirtCannon
 */
abstract class TShirtCannonState {

    /**
     * enter is called when the t-shirt cannon enters this state.
     * @param tsc The t-shirt cannon.
     */
    abstract void enter(TShirtCannon tsc);

    /**
     * update is called when something calls the t-shirt cannon's update
     * function and this is the current state.
     * @param tsc The t-shirt cannon.
     */
    void update(TShirtCannon tsc) {
        /*
         * If button 8 on ether joystick or button 9 on the gigaware is pressed,
         * change to the safety state. If button 6 on ether joystick or button 4
         * on the gigaware is pressed, change to the disabled state. This is so
         * that you can get to the safety state or the disalbed state from any
         * state.
         */
        if (tsc.getLeftStick().getRawButton(6) || tsc.getRightStick().getRawButton(6) || tsc.getGigaware().getRawButton(4)) {
            tsc.changeState(DisabledState.instance());
        }

        //Disable left cannon
        if (tsc.getLeftStick().getRawButton(3) && !tsc.getDebounce(1)) {
            tsc.setEnabled(1, !tsc.getEnabled(1));
            tsc.setDebounce(1, true);
        } else if (!tsc.getLeftStick().getRawButton(3)) {
            tsc.setDebounce(1, false);
        }

        //Disable right cannon
        if (tsc.getRightStick().getRawButton(3) && !tsc.getDebounce(2)) {
            tsc.setEnabled(2, !tsc.getEnabled(2));
            tsc.setDebounce(2, true);
        } else if (!tsc.getRightStick().getRawButton(3)) {
            tsc.setDebounce(2, false);
        }
    }

    /**
     * exit is called when the t-shirt cannon enters this state.
     * @param tsc The t-shirt cannon.
     */
    abstract void exit(TShirtCannon tsc);

    /**
     * getName is called to get the name of this state.
     * @return The name of this state.
     */
    abstract String getName();
}
